/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 08 - 28
 * Time: 13:28
 */
//牛客 二叉搜索树与双向链表
public class Solution5 {
    //法一 官方推荐方法 递归
    TreeNode head = null;
    TreeNode curPre = null;
    public TreeNode Convert(TreeNode pRootOfTree) {
        ConvertF(pRootOfTree);
        return head;
    }
    public void ConvertF(TreeNode pRootOfTree) {
        if(pRootOfTree == null) return;
        ConvertF(pRootOfTree.left);//相当于中序遍历
        if(curPre == null) {
            curPre = pRootOfTree;
            head = pRootOfTree;
        }else {
            curPre.right = pRootOfTree;
            pRootOfTree.left = curPre;
            curPre = pRootOfTree;
        }
        ConvertF(pRootOfTree.right);
    }
}
